package com.cgsd.heyu.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.cgsd.heyu.R;

/**
 * @author xiaoxing
 * Description 说明
 * CreateData: 2020/11/3
 */
public abstract class BaseDialog<T> extends Dialog {
    protected Context mContext;
    protected T data;

    public BaseDialog(@NonNull Context context,T data) {
        super(context, R.style.dialog_custom);
        this.mContext = context;
        this.data = data;
        setContentView(getLayoutId());
        Window window = this.getWindow();
        if (window != null) {
            window.setGravity(Gravity.CENTER);
        }
        setCanceledOnTouchOutside(false);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        // 获取屏幕宽、高用
        DisplayMetrics d = mContext.getResources().getDisplayMetrics();
        // 宽度设置为屏幕的0.7
        lp.width = (int) (d.widthPixels * 0.8);
        dialogWindow.setAttributes(lp);
        initView();
    }

    /**
     * 布局id
     * @return
     */
    protected abstract int getLayoutId();

    /**
     * 初始化view
     */

    protected abstract void initView();

}
